package com.example.javamaday.leetcode;

import com.example.javamaday.leetcode.base.ListNode;

public class LeetCodeTest0082 {


    public static void main(String[] args) {

    }


    public ListNode deleteDuplicates(ListNode head) {
        ListNode dumpy = new ListNode(Integer.MIN_VALUE);
        ListNode pre = dumpy;
        ListNode current = head;
        while (current != null) {
            // 判断是否出现重复，出现则去重
            if (current.next != null && current.val == current.next.val) {
                int temp = current.val;
                while (current != null && current.val == temp) {
                    current = current.next;
                }
            } else {
                ListNode next = current.next;
                current.next = null;
                pre.next = current;
                pre = current;
                current = next;
            }
        }
        return dumpy.next;
    }


}
